﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace UserInterface
{
    public class UI
    {
        SFX.TextureManager UITextures;
        SpriteBatch spriteBatch;

        public UI()
        {
            spriteBatch = RoyalRumble.MainGame.spriteBatch;
            UITextures = new SFX.TextureManager(RoyalRumble.MainGame.theContent);
            LoadUITextures();
        }
        public void LoadUITextures()
        {
            UITextures.AddFont("UIFONT", "Fonts/UIFont");
            UITextures.AddTexture("UIBG", "UI/UIBg");
            UITextures.AddTexture("Player1Bubble", "UI/Player1Bubble");
            UITextures.AddTexture("Player2Bubble", "UI/Player2Bubble");
            UITextures.AddTexture("Player3Bubble", "UI/Player3Bubble");
            UITextures.AddTexture("Player4Bubble", "UI/Player4Bubble");
            UITextures.AddTexture("WINSCREEN", "UI/EndGame/WinScreen");
        }

        public void Update(float ElapsedTime)
        {
        }
        public void RenderWinScreen(float ElapsedTime)
        {
            spriteBatch.Draw(UITextures.GetTexture("WINSCREEN"), new Vector2(278, 108), Color.White);

            if (States.GameplayState.Instance.GameSession.Player1.PlayerActive)
            {
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Kills.ToString(), new Vector2(460, 517), Color.Black);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Deaths.ToString(), new Vector2(460, 617), Color.Black);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Accuracy.ToString() + "%", new Vector2(460, 720), Color.Black);
            }
            if (States.GameplayState.Instance.GameSession.Player2.PlayerActive)
            {
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player2.Kills.ToString(), new Vector2(795, 517), Color.Black);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player2.Deaths.ToString(), new Vector2(795, 617), Color.Black);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player2.Accuracy.ToString() + "%", new Vector2(795, 720), Color.Black);
            }
            if (States.GameplayState.Instance.GameSession.Player3.PlayerActive)
            {
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player3.Kills.ToString(), new Vector2(1140, 517), Color.Black);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player3.Deaths.ToString(), new Vector2(1140, 617), Color.Black);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player3.Accuracy.ToString() + "%", new Vector2(1140, 720), Color.Black);
            }
            if (States.GameplayState.Instance.GameSession.Player4.PlayerActive)
            {
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player4.Kills.ToString(), new Vector2(1451, 517), Color.Black);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player4.Deaths.ToString(), new Vector2(1451, 617), Color.Black);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player4.Accuracy.ToString() + "%", new Vector2(1451, 720), Color.Black);
            }
        }
        public void Render(float ElapsedTime)
        {
            spriteBatch.Draw(UITextures.GetTexture("UIBG"), new Vector2(0, 0), Color.White);
            
            if (States.GameplayState.Instance.GameSession.Player1.PlayerActive)
            {
                spriteBatch.Draw(UITextures.GetTexture("Player1Bubble"), new Vector2(-10, 0), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Health.ToString() + "%", new Vector2(100, 10), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Kills.ToString(), new Vector2(70, 45), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Deaths.ToString(), new Vector2(107, 82), Color.White);
            }

            if (States.GameplayState.Instance.GameSession.Player2.PlayerActive)
            {
                spriteBatch.Draw(UITextures.GetTexture("Player2Bubble"), new Vector2(1575, 0), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player2.Health.ToString() + "%", new Vector2(1690, 10), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player2.Kills.ToString(), new Vector2(1660, 45), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player2.Deaths.ToString(), new Vector2(1690, 82), Color.White);
            }

            if (States.GameplayState.Instance.GameSession.Player3.PlayerActive)
            {
                spriteBatch.Draw(UITextures.GetTexture("Player3Bubble"), new Vector2(-10, 960), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player3.Health.ToString() + "%", new Vector2(100, 970), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player3.Kills.ToString(), new Vector2(70, 1006), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player3.Deaths.ToString(), new Vector2(107, 1042), Color.White);
            }

            if (States.GameplayState.Instance.GameSession.Player4.PlayerActive)
            {
                spriteBatch.Draw(UITextures.GetTexture("Player1Bubble"), new Vector2(1575, 960), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Health.ToString() + "%", new Vector2(1690, 970), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Kills.ToString(), new Vector2(1660, 1006), Color.White);
                spriteBatch.DrawString(UITextures.GetFont("UIFONT"), States.GameplayState.Instance.GameSession.Player1.Deaths.ToString(), new Vector2(1690, 1042), Color.White);
            }

            if (States.GameplayState.Instance.GameSession.GameOver)
            {
                RenderWinScreen(ElapsedTime);
            }
        }
    }
}